//
//  TransRuleViewController.m
//  FruitsWholesaler
//
//  Created by sgone-2 on 15/12/7.
//  Copyright © 2015年 sgone. All rights reserved.
//

#import "TransRuleViewController.h"
#define rowHeight 50
@interface TransRuleViewController ()
@property(nonatomic,strong) UITextField *textJL;
@property(nonatomic,strong) UITextField *textYF;
@property(nonatomic,strong) UITextField *textDS;
@property(nonatomic,strong) UITextField *textZJYF;

@end

@implementation TransRuleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleLabel.text = @"运费规则";
    self.titleLabel.font = [UIFont boldSystemFontOfSize:19];
    self.backBtn.hidden = NO;
    self.rightBut.hidden = NO;
    
    
    [self.rightBut setTitle:@"确定" forState:UIControlStateNormal];
    self.rightBut.titleLabel.font = [UIFont systemFontOfSize:17];
    self.view.backgroundColor = BACKGROUND1;
    
    [self initView];
    
    
}

-(void)back:(id)sender
{


    [self dismissViewControllerAnimated:YES completion:nil];

}



#pragma mark 进行距离保存数据
-(void)initView
{
    
    
    
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 84, ViewWidth, rowHeight)];
    view1.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view1];

    

    UILabel *lbl1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, rowHeight)];
    lbl1.textColor = [UIColor grayColor];
    lbl1.font = [UIFont systemFontOfSize:16];
    [view1 addSubview:lbl1];
    lbl1.text = @"  送货距离";
    
    
    self.textJL = [[UITextField alloc]initWithFrame:CGRectMake(85, 0, rowHeight, rowHeight)];
    self.textJL.borderStyle = UITextBorderStyleRoundedRect;
    self.textJL.keyboardType = UIKeyboardTypeNumberPad;
    self.textJL.textAlignment = NSTextAlignmentCenter;
    
    
    [view1 addSubview:self.textJL];
    
    
    UILabel *lbl2 = [[UILabel alloc]initWithFrame:CGRectMake(140, 0, 50, 50)];
    lbl2.textColor = [UIColor grayColor];
    lbl2.font = [UIFont systemFontOfSize:16];
    [view1 addSubview:lbl2];
    lbl2.text = @"公里内";

    
    UIView *view22 = [[UIView alloc]initWithFrame:CGRectMake(0, 84+51, ViewWidth, 50)];
    view22.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view22];
    
    UILabel *lbl3 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
    lbl3.textColor = [UIColor grayColor];
    lbl3.font = [UIFont systemFontOfSize:16];
    [view22 addSubview:lbl3];
    lbl3.text = @"   运费";
    
    
    self.textYF = [[UITextField alloc]initWithFrame:CGRectMake(85, 0, 50, 50)];
    self.textYF.borderStyle = UITextBorderStyleRoundedRect;
    self.textYF.keyboardType = UIKeyboardTypeNumberPad;
    self.textYF.textAlignment = NSTextAlignmentCenter;
    [view22 addSubview:self.textYF];
    
    
    UILabel *lbl4 = [[UILabel alloc]initWithFrame:CGRectMake(140, 0, 35, 50)];
    lbl4.textColor = [UIColor grayColor];
    lbl4.font = [UIFont systemFontOfSize:16];
    [view22 addSubview:lbl4];
    lbl4.text = @"元";

    
    
    
    //第二行数据
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 84+51*2, ViewWidth, 50)];
    view2.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view2];
    
    
    UILabel *lbl21 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
    lbl21.textColor = [UIColor grayColor];
    lbl21.font = [UIFont systemFontOfSize:16];
    [view2 addSubview:lbl21];
    lbl21.text = @"  起送店数";
    
    
    self.textDS = [[UITextField alloc]initWithFrame:CGRectMake(85, 0, 50, 50)];
    self.textDS.keyboardType = UIKeyboardTypeNumberPad;
    self.textDS.borderStyle = UITextBorderStyleRoundedRect;
    self.textDS.textAlignment = NSTextAlignmentCenter;
    [view2 addSubview:self.textDS];
    
    
    
    UILabel *lbl22 = [[UILabel alloc]initWithFrame:CGRectMake(140, 0, 50, 50)];
    lbl22.textColor = [UIColor grayColor];
    lbl22.font = [UIFont systemFontOfSize:16];
    [view2 addSubview:lbl22];
    lbl22.text = @"个";
    

  
    
    //第三行数据
    UIView *view3= [[UIView alloc]initWithFrame:CGRectMake(0, 84+51+51*2, ViewWidth, 50)];
    view3.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view3];

    
    
    UILabel *lbl31 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 175, 50)];
    lbl31.textColor = [UIColor grayColor];
    lbl31.font = [UIFont systemFontOfSize:16];
    [view3 addSubview:lbl31];
    lbl31.text = @"  超过送货距离增加运费";

    
    
    
    
    self.textZJYF = [[UITextField alloc]initWithFrame:CGRectMake(180, 0, 50, 50)];
    self.textZJYF.keyboardType = UIKeyboardTypeNumberPad;
    self.textZJYF.borderStyle = UITextBorderStyleRoundedRect;
    self.textZJYF.textAlignment = NSTextAlignmentCenter;
    [view3 addSubview:self.textZJYF];
    
    
    UILabel *label33 = [[UILabel alloc]initWithFrame:CGRectMake(235, 0, 40, 40)];
    label33.text = @"元";
    label33.font = [UIFont systemFontOfSize:16];
    label33.textColor = [UIColor grayColor];
    
    [view3 addSubview:label33];
    

    
    
    
    
    


}


-(void)rightButClick:(id)sender
{


    if (self.textJL.text.length == 0 || self.textYF.text.length == 0 || self.textDS.text.length == 0 || self.textZJYF.text.length == 0) {
        
        
        [self.view makeToast:@"请完善信息"];
        return;
        
        
    }
    else
    {
    
        
        
        //保存数据到单列
        self.dataHandler.juli = self.textJL.text;
        self.dataHandler.yunfei = self.textYF.text;
        self.dataHandler.dianshu = self.textDS.text;
        self.dataHandler.zjyunfei = self.textZJYF.text;
        
    
    //通过block传值传递到上一个页面
    NSArray *array = [[NSArray alloc]init];
    
    array= [NSArray arrayWithObjects:self.textJL.text,self.textYF.text,self.textDS.text,self.textZJYF.text, nil];
    

    //传值传递到上一个界面
    if (self.block) {
        
        self.block(array);
    }

    
    //通知进行数据刷新
    [[NSNotificationCenter defaultCenter] postNotificationName:@"shuaxian" object:nil];
    
    
    
    
    
        [self dismissViewControllerAnimated:YES completion:nil];
    
//    [self.navigationController popViewControllerAnimated:YES];

    }
}

@end
